package com.learn.annotation_config.configuration.imports;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;

/**
 * 实现ImportSelector可自定义导入规则
 */
public class ImportSelectorImpl implements ImportSelector {
    @Override
    public String[] selectImports(AnnotationMetadata importingClassMetadata) {
        // AnnotationMetadata：导入当前类的@Import注解所在类的其他注解原信息
        String[] basePackages = (String[]) importingClassMetadata.getAnnotationAttributes(
                ComponentScan.class.getName()
        ).get("basePackages");
        // com.learn.annotation_config.configuration
        System.out.println(basePackages[0]);
        
        // 返回满足条件的被@Import的类全限定名数组
        return new String[]{ImportConfiguration2.class.getName()};
    }
}
